package com.ashin.leetcode;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * 给你一个整数数组 nums ，判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i != j、i != k 且 j != k ，
 * 同时还满足 nums[i] + nums[j] + nums[k] == 0 。请
 * 你返回所有和为 0 且不重复的三元组。
 *
 * @author ashin
 */
public class L0015 {


    @Test
    public void test() {
        int[]nums = {-1,0,1,2,-1,-4};
        System.out.println(threeSum(nums));
    }


    public List<List<Integer>> threeSum(int[] nums) {
        Set<Set<Integer>> resultList = new TreeSet<>();

        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                for (int k = j + 1; k < nums.length; k++) {
                    if (nums[i] + nums[j] + nums[k] == 0) {
                        Set<Integer> one = new TreeSet<>();
                        one.add(nums[i]);
                        one.add(nums[j]);
                        one.add(nums[k]);

                        resultList.add(one);
                    }
                }
            }
        }

        List<List<Integer>> f=new ArrayList<>();
        System.out.println(resultList);

        return new ArrayList<List<Integer>>(f);
    }

}
